<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        const obj = {
            title: 'linux',
            expand: true,
            children: [
                {
                    title: 'test1', children: [
                        { title: '测试11.py', path: 'test11.py', checked: false },
                        { title: '测试12.py', path: 'test12.py', checked: false }
                    ]
                },
                {
                    title: 'test2', children: [
                        { title: '测试21.py', path: 'test21.py', checked: false },
                        { title: '测试22.py', path: 'test22.py', checked: false }
                    ]
                },

                {
                    title: '测试3.py', path: 'test3.py', children: [
                        { title: '测试31', path: 'test31.py', checked: false },
                        { title: '测试32', path: 'test32.py', checked: false },
                        {
                            title: '测试33', children: [
                                { title: '测试331', path: 'test331.py', checked: false },
                                {
                                    title: '测试332', path: 'test332.py', children: [
                                        { title: '测试3321', path: 'test3321.py', checked: false },
                                        { title: '测试3322', path: 'test3322.py', checked: false },
                                    ]
                                },
                            ]
                        }
                    ]
                },
                { title: '测试4.py', path: 'test4.py', checked: false },
                { title: '测试5.py', path: 'test5.py', checked: false },
                { title: '测试6.py', path: 'test6.py', checked: false },
                { title: '测试7.py', path: 'test7.py', checked: false },
                { title: '测试8.py', path: 'test8.py', checked: false }
            ]
        }
// 转换成 arr打印的结果
        let arr = []
        function get(cc) {
            for (let item of cc) {
                delete item.checked
                if (item.children) {
                    get(item.children, arr)
                } else {
                    arr.push(item)
                }
            }
        }
        get(obj.children)                   //  递归里不会用return 拿不到arr，所以只好外部定义了。
        console.log(arr)
        // let arr = []
        // for (let i1 of obj.children) {
        //     if(i1.children) {
        //         for(let i2 of i1.children) {
        //             if(i2.children) {
        //                 for(let i3 of i2.children) {
        //                    if(i3.children) {
        //                        for(let i4 of i3.children) {
        //                            arr.push(i4)
        //                        }
        //                    } else {
        //                        arr.push(i3)
        //                    }
        //                 }
        //             } else {
        //                 arr.push(i2)
        //             }
        //         }
        //     } else {
        //         arr.push(i1)
        //     }
        // }
               // for (let item of arr) {
        //     for(let i in item) {
        //         if(i=='checked'||i=='children') {
        //             delete item.checked
        //             // delete item.children
        //         }
        //     }
        // }
        // let cc = {a:1,b:2}
        // for(let item in cc) {
        //     if(item == 'a') {
        //         delete cc.a           //delete 后边要跟指定的属性名 具体到a,而不能用item代替
        //     }
        // }

        // console.log(cc)

    </script>
</body>

</html>